<template>
  <div class="app-container">
    <div class="search-bar">
      <el-select v-model="searchData.jsyId" placeholder="请选择技术员查询">
        <el-option label="全部" value=""></el-option>
        <el-option
          v-for="item in jsyList"
          :key="item.jsyId"
          :label="item.jsyxm"
          :value="item.jsyId"
        ></el-option>
      </el-select>
      <el-date-picker
        v-model="searchData.year"
        type="year"
        placeholder="请选择年度查询"
        value-format="yyyy"
      >
      </el-date-picker>
      <el-button
        v-waves
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="searchBtnHandle"
        >查询</el-button
      >
      <el-button
        v-waves
        type="info"
        size="small"
        icon="el-icon-refresh"
        @click="resetTableList"
        >显示全部</el-button
      >
      <div style="float: right"></div>
    </div>
    <!-- 地块管理表-列表 -->
    <el-table
      ref="dataTable"
      :data="tableData"
      stripe
      border
      v-loading="isLoading"
    >
      <el-table-column
        type="selection"
        width="50"
        align="center"
        header-align="center"
      />
      <el-table-column label="技术员" prop="jsyxm" align="center" />
      <el-table-column label="种植计划数" prop="jhs" align="center" />
      <el-table-column label="总面积（亩）" prop="dkmj" align="center" />
      <el-table-column label="地块总收益(元)" prop="sr" align="center" />
      <el-table-column label="任务数" prop="rws" align="center" />
      <el-table-column label="日报数" prop="rbs" align="center" />
    </el-table>
    <!-- 地块管理表-分页 -->
    <el-pagination
      style="text-align: center; margin-top: 10px"
      layout="total,prev,pager,next,sizes,jumper"
      :page-size="pager.limit"
      :current-page="pager.page"
      :total="pager.totalCount"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  data() {
    return {
      searchData: {},
      tableData: [],
      yearList: [],
      pager: {
        page: 1,
        limit: 10,
        totalCount: 0,
      },
      isLoading: false,
      url: {
        list: "/jtnc/bigdata/listJsyjx",
        jsyList: "/jtnc/jsydagl/krJsydagl/select",
      },
      jsyList: [],
    };
  },
  created() {
    this.loadTableList();
    this.getJsyList();
  },
  methods: {
    loadTableList() {
      this.isLoading = true;
      const params = { ...this.pager, ...this.searchData };
      request({
        url: this.url.list,
        method: "get",
        params,
      }).then((response) => {
        const { data } = response;
        this.pager.totalCount = data.total;
        this.tableData = data.records;
        this.isLoading = false;
      });
    },
    // 监听分页
    handleCurrentChange(page) {
      this.pager.page = page;
      this.loadTableList();
    },
    // 分页条数改变
    handleSizeChange(size) {
      this.pager.limit = size;
      this.loadTableList();
    },
    // 查询按钮
    searchBtnHandle() {
      this.pager.page = 1;
      this.loadTableList();
    },
    // 显示全部
    resetTableList() {
      this.pager.page = 1;
      this.searchData = {};
      this.timePickageValue = "";
      this.loadTableList();
    },
    // 获取地块下拉
    getJsyList() {
      request({
        url: this.url.jsyList,
        method: "get",
      }).then((response) => {
        const { data } = response;
        this.jsyList = data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.search-bar {
  margin-bottom: 10px;
  ::v-deep {
    .el-input,
    .el-select {
      width: 180px;
      margin-right: 10px;
      margin-bottom: 5px;
    }
  }
}
</style>
